﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CCUiLMCopyLocationOrientationValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.ObjectModel;
using System.Resources;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands;

public class CCUiLMCopyLocationOrientationValidator : ITxValidator
{
  private ITxTypeFilter _filter;
  private ResourceManager _resMng;

  public CCUiLMCopyLocationOrientationValidator()
  {
    this._filter = (ITxTypeFilter) new TxTypeFilter(typeof (ITxLocationOperation));
    this._resMng = new ResourceManager("DnProcessSimulateCommands.StringTable", this.GetType().Assembly);
  }

  public bool IsValidObject(ITxObject obj, out string errorMessage)
  {
    errorMessage = (string) null;
    bool flag = this._filter.DoesPassFilter(obj);
    TxWeldLocationOperation locationOperation = obj as TxWeldLocationOperation;
    if (TxWeldLocationOperation.op_Inequality(locationOperation, (ITxObject) null) && !locationOperation.IsProjected)
    {
      errorMessage = string.Format(this._resMng.GetString("AUTO_PATH_PLAN_NON_PROJECTED_LOC_TOOLTIP"), (object) obj.Name);
      return false;
    }
    if (!flag)
    {
      switch (obj)
      {
        case ITxCompoundOperation _:
        case ITxLocationOperation _:
          errorMessage = (string) null;
          break;
        default:
          errorMessage = string.Format(this._resMng.GetString("COPY_LOC_INVALID_TYPE"), (object) obj.Name);
          break;
      }
    }
    return flag;
  }

  public bool IsValidText(string text, out string errorMessage)
  {
    errorMessage = (string) null;
    bool flag = false;
    if (text == "")
      errorMessage = string.Format(this._resMng.GetString("COPY_LOC_EMPTY_SELECTION"));
    else if (this.GetObject(text) != null)
      flag = true;
    else
      errorMessage = string.Format(this._resMng.GetString("COPY_LOC_INVALID_TYPE"), (object) text);
    return flag;
  }

  public ITxObject GetObject(string text)
  {
    ITxObject itxObject = (ITxObject) null;
    TxObjectList objectsByName = TxApplication.ActiveDocument.GetObjectsByName(text);
    for (int index = 0; index < ((Collection<ITxObject>) objectsByName).Count && itxObject == null; ++index)
    {
      if (this._filter.DoesPassFilter(((Collection<ITxObject>) objectsByName)[index]))
        itxObject = ((Collection<ITxObject>) objectsByName)[index];
    }
    return itxObject;
  }

  public string GetText(ITxObject obj)
  {
    string text = (string) null;
    try
    {
      text = obj.Name;
    }
    catch (Exception ex)
    {
    }
    return text;
  }
}
